﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
using System.Web.Configuration;
namespace NCKH.Personal
{
    public partial class banTTTCHT : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                hienmanhanghiencuu();
            }
        }

        protected void hienmanhanghiencuu()
        {
            string connection = ConfigurationManager.ConnectionStrings["NCKH"].ConnectionString;
            string select_NNC = "SELECT MaNNC, TenNNC FROM NHANGHIENCUU";
            using (SqlConnection cnn = new SqlConnection(connection))
            {
                using (SqlCommand cmd = new SqlCommand(select_NNC, cnn))
                {
                    cnn.Open();
                    cmd.CommandType = CommandType.Text;
                    using (SqlDataReader rd = cmd.ExecuteReader())
                    {
                        drdma.Items.Insert(0, "--Chọn NNC---");
                        if (rd.HasRows)
                        {
                            while (rd.Read())
                            {
                                drdma.Items.Add(new ListItem(rd["TenNNC"].ToString(), rd["MaNNC"].ToString()));
                            }

                        }
                        else
                            btgui.Enabled = false;
                        rd.Close();
                    }
                    cnn.Close();
                }
            }
        }
        protected void txthoten_TextChanged(object sender, EventArgs e)
        {

        }

        protected void cldngaynopTM_SelectionChanged(object sender, EventArgs e)
        {
            txtthoigian.Text = cldngaynopTM.SelectedDate.ToShortDateString();
        }

        protected void btgui_Click(object sender, EventArgs e)
        {
            string connection = ConfigurationManager.ConnectionStrings["NCKH"].ConnectionString;
            using (SqlConnection cnn = new SqlConnection(connection))
            {
                using (SqlCommand cmd = new SqlCommand("insert_banTTTCHT", cnn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@Thoigiandexuat", txtthoigian.Text);
                    cmd.Parameters.AddWithValue("@Dutrukinhphi", txtkinhphi.Text);
                    cmd.Parameters.AddWithValue("@Songuoithamgia", txtsonguoi.Text);
                    cmd.Parameters.AddWithValue("@MaNNC", drdma.SelectedValue);
                    cnn.Open();
                    cmd.ExecuteNonQuery();
                    cnn.Close();
                    Response.Write("<script>alert('Bạn đã gửi thông tin thành công, thông tin sẽ được xét duyệt và phản hồi trong khoảng thời gian sớm nhất!!!, chúc bạn 1 ngày vui vẻ')</script>");
                    txtsonguoi.Text = txtthoigian.Text = txtdonvi.Text = txthoten.Text = txtkinhphi.Text = string.Empty;
                }
            }
        }

        protected void btin_Click(object sender, EventArgs e)
        {

        }

        protected void bthuy_Click(object sender, EventArgs e)
        {
            txtsonguoi.Text = txtthoigian.Text = txtdonvi.Text = txthoten.Text = txtkinhphi.Text = string.Empty;
        }
    }
}